/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.procurement.service;

import com.javaeye.delivery.dao.CheckOrderDAO;
import com.javaeye.procurement.dao.MaterialsReceiveOrderDAO;
import com.javaeye.procurement.dto.MaterialsReceiveOrder;
import com.javaeye.delivery.dto.OrderCheck;
import com.javaeye.common.util.DateUtils;

public class MaterialsReceiveCheckService implements IMaterialsReceiveCheckService {
	
	private CheckOrderDAO dao;
	
	private MaterialsReceiveOrderDAO orderDao;
	
	public void setDao(CheckOrderDAO dao) {
		this.dao = dao;
	}

	public void setOrderDao(MaterialsReceiveOrderDAO orderDao) {
		this.orderDao = orderDao;
	}

	public void saveCheckResult(MaterialsReceiveOrder order, OrderCheck checkResult) {
		//保存检验信息
		dao.saveCheckResult(checkResult);
		if (Integer.parseInt(checkResult.getResult()) == 2) {
			order.setStatus(MaterialsReceiveOrder.ORDER_STATES_CREATED_UNQUALIFIED);
		} else {
			order.setStatus(MaterialsReceiveOrder.ORDER_STATES_CHECK_QUALIFIED);
		}
		order.setUpdateDate(DateUtils.now());
		orderDao.saveMaterialsReceiveOrder(order);
	}
}
